﻿using System;
using System.Data;
using System.Windows.Forms;
using DevExpress.XtraBars;
using UniMana.Data;
using UniMana.Utils.Data;
using UniMana.Utils.Helper;
namespace UniMana.Win.Leadership
{
    public partial class FrmReport_SubSubjectClass_Subject : DevExpress.XtraEditors.XtraForm
    {

        private DBMain m_ReportTrainingSubject_Class = new DBMain();
        private const int ACTION_NO = 0;
        DataTable dt = new DataTable();
        public FrmReport_SubSubjectClass_Subject()
        {
            InitializeComponent();
            InitControlEvent();
        }
        public void InitControlEvent()
        {
            this.xucBar1.btnPrint_Click += 
                new UniMana.Utils.Controls.xucBar.ButtonClickHandler(
                    this.btnPrint_Click);
            //this.xucBar1.btnExport_Click += 
            //new UniMana.Utils.Controls.xucBar.ButtonClickHandler(
            //    this.btnExportExcel_Click);
        }
        private void btnPrint_Click(object sender, ItemClickEventArgs e)
        {
            pringrcTrainingSubject_Class_SubHienThi.ShowPreviewDialog();
        }

        private void FrmReportSubjectClass_Subject_Load(object sender, EventArgs e)
        {
            lueCatalogue_SchoolYears.GetData(
                m_ReportTrainingSubject_Class.m_DCReadOnly.Catalogue_SchoolYears, 
                "Catalogue_SchoolYearKey",
                "Name");
            lueCatalogue_Terms.GetData(
                m_ReportTrainingSubject_Class.m_DCReadOnly.Catalogue_Terms, 
                "Catalogue_TermKey",
                "Name");
          
        }

        private void btnView_Click(object sender, EventArgs e)
        {
            if (lueCatalogue_SchoolYears != null && lueCatalogue_Terms != null )
            {
               grcTrainingSubject_Class_Sub.DataSource = 
                   m_ReportTrainingSubject_Class.m_DCReadOnly.
                   Training_Subject_Classes.TrainingSubject_Class_Sub(
                   m_ReportTrainingSubject_Class.m_DCReadOnly.Catalogue_Departments, 
                   m_ReportTrainingSubject_Class.m_DCReadOnly.Catalogue_Terms, 
                   m_ReportTrainingSubject_Class.m_DCReadOnly.Training_Subjects, 
                   m_ReportTrainingSubject_Class.m_DCReadOnly.Catalogue_SchoolYears, 
                   this.lueCatalogue_Terms.GetIntValue(), this.lueCatalogue_SchoolYears.GetIntValue());
                
                //DataTable dt = 
                //m_ReportTrainingSubject_Class.m_DCReadOnly.Training_Subject_Classes.TrainingSubject_Class_Sub(
                //    m_ReportTrainingSubject_Class.m_DCReadOnly.Catalogue_Departments, 
                //    m_ReportTrainingSubject_Class.m_DCReadOnly.Catalogue_Terms, 
                //    m_ReportTrainingSubject_Class.m_DCReadOnly.Training_Subjects, 
                //    m_ReportTrainingSubject_Class.m_DCReadOnly.Catalogue_SchoolYears, 
                //    this.lueCatalogue_Terms.GetIntValue(), 
                //    this.lueCatalogue_SchoolYears.GetIntValue()).ToDataTable();
                //dt.Columns.Add("STT");
                //for (int i = 0; i < dt.Rows.Count; i++)
                //{
                //    dt.Rows[i]["STT"] = i + 1;
                //}
                //this.grcTrainingSubject_Class_Sub.DataSource = dt;
                 grvTrainingSubject_Class_Sub.ExpandAllGroups();
            }
        }

        /// <summary>
        /// sự kiện enter
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            switch (keyData)
            {
                case Keys.Enter:
                    {

                        if (lueCatalogue_SchoolYears != null && lueCatalogue_Terms != null )
                        {
                            grcTrainingSubject_Class_Sub.DataSource = 
                                m_ReportTrainingSubject_Class.m_DCReadOnly.
                                Training_Subject_Classes.TrainingSubject_Class_Sub(
                                m_ReportTrainingSubject_Class.m_DCReadOnly.Catalogue_Departments, 
                                m_ReportTrainingSubject_Class.m_DCReadOnly.Catalogue_Terms, 
                                m_ReportTrainingSubject_Class.m_DCReadOnly.Training_Subjects, 
                                m_ReportTrainingSubject_Class.m_DCReadOnly.Catalogue_SchoolYears, 
                                this.lueCatalogue_Terms.GetIntValue(), 
                                this.lueCatalogue_SchoolYears.GetIntValue());
                                                     
                            grvTrainingSubject_Class_Sub.ExpandAllGroups();
                        }
                    }
                    return true;
                default:
            break;
            }

            return base.ProcessCmdKey(ref msg, keyData);
        }
        private void btnPrint_Click(object sender, EventArgs e)
        {
            pringrcTrainingSubject_Class_SubHienThi.ShowPreview();
        }

    }
}

